% Display app res, phase & asso errors
% with impedance tensor & erros as input
% tested 9/11/02 -ok
% changed the error bar plotting 12/11/02
% known bug - if (Rhxy - RhxyErr/2) <0, log plot will propmt an error message
% latest date 13.10.2002

function[r,p,er,ep] = compresph(tf,ProcDef),

frq=ProcDef.TLFreq1;
file=ProcDef.file1;
nfrq = length(frq);

for i = 1:nfrq,   
   p(1,i) = atan2(imag(tf(i,1)),real(tf(i,1))) * 180 / 3.1415926535897;
   r(1,i) = 0.2 * (1/frq(i)) * (tf(i,1) * conj(tf(i,1)));
   p(2,i) = (atan2(imag(tf(i,2)),real(tf(i,2))) * 180 / 3.1415926535897);
   r(2,i) = 0.2 * (1/frq(i)) * (tf(i,2) * conj(tf(i,2)));
end;

k=find(p(2,:)>-180&p(2,:)<-90);
p(2,k)=p(2,k)+180;
k=find(p(1,:)<-180&p(1,:)<-90);
p(1,k)=p(1,k)+180;

k=find(p(2,:)>-90&p(2,:)<-0);
p(2,k)=p(2,k)+90;
k=find(p(1,:)>-90&p(1,:)<-0);
p(1,k)=p(1,k)+90;


ep(1,:) = ((tf(:,5)./abs(tf(:,1)))*(180/pi))'; 
ep(2,:) = ((tf(:,6)./abs(tf(:,2)))*(180/pi))';
er(1,:) = ((tf(:,5).*abs(tf(:,1))./frq') * 0.4)'; % bit confusion. may be ok -dt 2.8.2
er(2,:) = ((tf(:,6).*abs(tf(:,2))./frq') * 0.4)';
